-
Notifications
You must be signed in to change notification settings - Fork 0
/
Birthday_Cake_Candles.c
76 lines (70 loc) · 2.44 KB
/
Birthday_Cake_Candles.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/**
* @Repository HackerRank Soulutions
* @file birthday Cake Candle
* @author Abdelrahman Ahmed Moussa ([email protected])
* @copyright Copyright (c) 2024
*
*/
/*------------------------------------------------------------------------------*/
/* */
/* birthday Cake Candle */
/* */
/*------------------------------------------------------------------------------*/
/*
* Complete the 'birthdayCakeCandles' function below.
*
* The function is expected to return an INTEGER.
* The function accepts INTEGER_ARRAY candles as parameter.
*/
/*------------------------------------------------------------------------------*/
/* */
/* Solution 01 */
/* */
/*------------------------------------------------------------------------------*/
int birthdayCakeCandles(int candles_count, int* candles)
{
int i;
//1-get max number
//2-count max number freq
//>>in the same loop
int max = candles[0];
int freq=1; //must be one not zero , because i assume candles[0] is the max so i have one
for (i=1 ; i<candles_count ; i++)
{
if(candles[i]>max)
{
max=candles[i];
freq=1;
}
else if ( candles[i]==max )
{
freq++;
}
}
return freq;
}
/*------------------------------------------------------------------------------*/
/* */
/* Solution 02 */
/* */
/*------------------------------------------------------------------------------*/
/*
int birthdayCakeCandles(int candles_count, int* candles)
{
int i,max=-1,counter;
for(i=0 ; i<candles_count ; i++)
{
//max=candles[i];
if(candles[i]>max)
{
max=candles[i];
counter=1;
}
else if (candles[i]==max)
{
counter++;
}
}
return counter;
}
*/